package com.example.HelloSpace.factory;

import android.app.Application;

import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import com.example.HelloSpace.database.AppDatabase;
import com.example.HelloSpace.viewmodels.SubscribedMissionsViewModel;

public class SubscribedMissionsViewModelFactory implements ViewModelProvider.Factory {

    private final AppDatabase appDatabase;
    private final Application application;

    public SubscribedMissionsViewModelFactory(Application application, AppDatabase appDatabase) {
        this.appDatabase = appDatabase;
        this.application = application;
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T extends ViewModel> T create(Class<T> modelClass) {
        if (modelClass.isAssignableFrom(SubscribedMissionsViewModel.class)) {
            return (T) new SubscribedMissionsViewModel(application, appDatabase);
        }
        throw new IllegalArgumentException("Unknown ViewModel class");
    }
}
